package makabakaquestionnaire.zutsoftware.framework.security.handle;

import com.alibaba.fastjson.JSON;
import makabakaquestionnaire.zutsoftware.constant.Result;
import makabakaquestionnaire.zutsoftware.utils.ServletUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ：wjf
 * @date ：Created in 2022/2/20 12:37
 * @description：退出成功处理类
 * @modified By：
 */
@Component
public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        //1.执行退出,销毁用户的token
        //2.记录用户退出日志
        //3.返回成功给客户端
        ServletUtils.renderString(response, JSON.toJSONString(Result.success("退出成功")));
    }
}
